home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / ccs_util.jar / com / commerceone / util / collection / PropertyDiff.class (.txt) < prev   
Encoding:
Java Class File  |  1999-12-09  |  2.0 KB  |  45 lines

  1. package com.commerceone.util.collection;
  2.  
  3. import com.commerceone.util.contract.Contract;
  4. import java.beans.PropertyChangeEvent;
  5. import java.util.Enumeration;
  6. import java.util.Hashtable;
  7. import java.util.Properties;
  8. import java.util.Vector;
  9.  
  10. public class PropertyDiff {
  11.    public static Enumeration getDifference(Object source, Properties oldProps, Properties newProps) {
  12.       Vector changes = new Vector();
  13.       Enumeration oldPropNames = oldProps.propertyNames();
  14.  
  15.       while(oldPropNames.hasMoreElements()) {
  16.          String oldName = oldPropNames.nextElement().toString();
  17.          Object oldValue = ((Hashtable)oldProps).get(oldName);
  18.          Contract.require(oldValue != null);
  19.          Object newValue = ((Hashtable)newProps).get(oldName);
  20.          if (newValue == null) {
  21.             PropertyChangeEvent pce = new PropertyChangeEvent(source, oldName, oldValue, (Object)null);
  22.             changes.addElement(pce);
  23.          } else if (!oldValue.equals(newValue)) {
  24.             PropertyChangeEvent pce = new PropertyChangeEvent(source, oldName, oldValue, newValue);
  25.             changes.addElement(pce);
  26.          }
  27.       }
  28.  
  29.       oldPropNames = newProps.propertyNames();
  30.  
  31.       while(oldPropNames.hasMoreElements()) {
  32.          String newName = oldPropNames.nextElement().toString();
  33.          Object newValue = ((Hashtable)newProps).get(newName);
  34.          Contract.require(newValue != null);
  35.          Object oldValue = ((Hashtable)oldProps).get(newName);
  36.          if (oldValue == null) {
  37.             PropertyChangeEvent pce = new PropertyChangeEvent(source, newName, (Object)null, newValue);
  38.             changes.addElement(pce);
  39.          }
  40.       }
  41.  
  42.       return changes.elements();
  43.    }
  44. }
  45.